package com.rentcars.controller;

import com.github.pagehelper.PageInfo;
import com.rentcars.entity.Carorder;
import com.rentcars.entity.Result;
import com.rentcars.service.CarorderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 罗孝天
 */
@RestController
public class CarorderControllrt {

    @Autowired
    private CarorderService carorderService;

    @RequestMapping("/delCarorder")
    public boolean deleteCarorder(String orderid){
        int a=carorderService.deleteByPrimaryKey(orderid);
        if (a>0){
            return true;
        }else {return false;}
    }

    @RequestMapping("carorderList")
    public List<Carorder> getCarorder(Carorder carorder){
        List<Carorder> list=new ArrayList<>();
        String orderid=carorderService.insert(carorder);
        Carorder order=carorderService.selectByPrimaryKey(orderid);
        list.add(order);
        return list;
    }



    @RequestMapping(value = "/getPage",method = RequestMethod.GET)
    public PageInfo<Carorder> queryCarOrderByPage(Integer curr, Integer pageSize){
        PageInfo<Carorder> carorderPageInfo=carorderService.queryCarOrderByPage(curr,pageSize);
        return carorderPageInfo;

    }


    @RequestMapping("/order-list")
    public ModelAndView toOrder(){
        return  new ModelAndView("order-list");
    }


    @RequestMapping("/editPagee")
    public ModelAndView findCarorder(Carorder carorder){
        Carorder c = carorderService.getCarorderById(carorder);
        Map<String,Object>rsMap =new HashMap<>();
        rsMap.put("data",c);
        return  new ModelAndView("adminedit",rsMap);
    }

    @RequestMapping("/adminedit")
   public Result adminedit(Carorder carorder){
        carorderService.updateCarorder(carorder);
        return  new  Result();
    }


}
